﻿using DeepZoomPivotConstructor.PivotLib;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace t_PivotLib
{
    
    
    /// <summary>
    ///This is a test class for PivotMetadataBaseTest and is intended
    ///to contain all PivotMetadataBaseTest Unit Tests
    ///</summary>
    [TestClass()]
    public class t_PivotMetadataBase
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for PivotMetadataBase Constructor
        ///</summary>
        [TestMethod()]
        public void TestURLCreate()
        {
            Uri u = new Uri("http://www.nytimes.com");
            var p = new PivotMetadataURL("link", "george", u);

            var o = p.ToFacetInfo();
            Assert.IsNotNull(o, "Expected a facet info object!");
            var lnk = o as DeepZoomPivotConstructor.PivotLib.PivotSchema.linkType;
            Assert.IsNotNull(lnk, "The returned item is not of hte right type!");
            Assert.AreEqual("george", lnk.Name, "Name of link isn't right");
            Assert.AreEqual("http://www.nytimes.com", lnk.Href, "The url isn't right!");
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestBadURLCreateNameBlank()
        {
            Uri u = new Uri("http://www.nytimes.com");
            var p = new PivotMetadataURL("link", "", u);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestBadURLCreateNameNull()
        {
            Uri u = new Uri("http://www.nytimes.com");
            var p = new PivotMetadataURL("link", null, u);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestBadURLCreateNameUrlNull()
        {
            Uri u = new Uri("http://www.nytimes.com");
            var p = new PivotMetadataURL("link", "george", null);
        }

        [TestMethod]
        public void TestStringCreate()
        {
            var p = new PivotMetadataString("str", "this is a test");

            var o = p.ToFacetInfo();
            Assert.IsNotNull(o, "Expected a facet info object!");
            var lnk = o as DeepZoomPivotConstructor.PivotLib.PivotSchema.stringType;
            Assert.IsNotNull(lnk, "The returned item is not of hte right type!");
            Assert.AreEqual("this is a test", lnk.Value, "Value of link isn't right");
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestBlankName()
        {
            var p = new PivotMetadataString("", "hi there");
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestNullName()
        {
            var p = new PivotMetadataString(null, "hi there");
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestBadStringCreateBlank()
        {
            var p = new PivotMetadataString("str", "");
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestBadStringCreateNull()
        {
            var p = new PivotMetadataString("str", null);
        }

        [TestMethod]
        public void TestNumberCreate()
        {
            var p = new PivotMetadataNumber("num", (decimal) 55.5);

            var o = p.ToFacetInfo();
            Assert.IsNotNull(o, "Expected a facet info object!");
            var lnk = o as DeepZoomPivotConstructor.PivotLib.PivotSchema.numberType;
            Assert.IsNotNull(lnk, "The returned item is not of hte right type!");
            Assert.AreEqual((decimal) 55.5, lnk.Value, "Value of link isn't right");
        }

        [TestMethod]
        public void TestNumberCreateNegCloseToBoundary()
        {
            var p = new PivotMetadataNumber("num", (decimal)-15.0000000000001);
            Assert.AreEqual((decimal)-15.0000000000001, p.Value, "meta data value");
            var o = p.ToFacetInfo();
            Assert.AreEqual((decimal)-15.0, (o as DeepZoomPivotConstructor.PivotLib.PivotSchema.numberType).Value, "facet value");
            
        }

        [TestMethod]
        public void TestDateTimeCreate()
        {
            var dtnow = DateTime.Now;
            var p = new PivotMetadataDateTime("date", dtnow);

            var o = p.ToFacetInfo();
            Assert.IsNotNull(o, "Expected a facet info object!");
            var lnk = o as DeepZoomPivotConstructor.PivotLib.PivotSchema.dateTimeType;
            Assert.IsNotNull(lnk, "The returned item is not of hte right type!");
            Assert.AreEqual(dtnow, lnk.Value, "Value of link isn't right");
        }
    }
}
